<?php

/**
 * formproblemevehicule form base class.
 *
 * @method formproblemevehicule getObject() Returns the current form's model object
 *
 * @package    forumCDE
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormGeneratedTemplate.php 29553 2010-05-20 14:33:00Z Kris.Wallsmith $
 */
abstract class BaseformproblemevehiculeForm extends BaseFormDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'id'                       => new sfWidgetFormInputHidden(),
      'dossier_id'               => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('dossier'), 'add_empty' => true)),
      'codevehicule_id'          => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('codevehicule'), 'add_empty' => false)),
      'eclatparabrise'           => new sfWidgetFormInputCheckbox(),
      'commentaire'              => new sfWidgetFormTextarea(),
      'created_at'               => new sfWidgetFormDateTime(),
      'updated_at'               => new sfWidgetFormDateTime(),
      'problemepneumatique_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'problemepneumatique')),
      'positioneclairage_list'   => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'positionprobleme')),
      'problememoteur_list'      => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'problememoteur')),
      'problemeniveau_list'      => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'problemeniveau')),
      'problemecarrosserie_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'problemecarrosserie')),
      'problemeeclairage_list'   => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'problemeeclairage')),
      'problemefreins_list'      => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'positionprobleme')),
      'positioncarrosserie_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'positionprobleme')),
      'positionpneumatique_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'positionprobleme')),
    ));

    $this->setValidators(array(
      'id'                       => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
      'dossier_id'               => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('dossier'), 'required' => false)),
      'codevehicule_id'          => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('codevehicule'))),
      'eclatparabrise'           => new sfValidatorBoolean(array('required' => false)),
      'commentaire'              => new sfValidatorString(array('required' => false)),
      'created_at'               => new sfValidatorDateTime(),
      'updated_at'               => new sfValidatorDateTime(),
      'problemepneumatique_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'problemepneumatique', 'required' => false)),
      'positioneclairage_list'   => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'positionprobleme', 'required' => false)),
      'problememoteur_list'      => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'problememoteur', 'required' => false)),
      'problemeniveau_list'      => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'problemeniveau', 'required' => false)),
      'problemecarrosserie_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'problemecarrosserie', 'required' => false)),
      'problemeeclairage_list'   => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'problemeeclairage', 'required' => false)),
      'problemefreins_list'      => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'positionprobleme', 'required' => false)),
      'positioncarrosserie_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'positionprobleme', 'required' => false)),
      'positionpneumatique_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'positionprobleme', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('formproblemevehicule[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function getModelName()
  {
    return 'formproblemevehicule';
  }

  public function updateDefaultsFromObject()
  {
    parent::updateDefaultsFromObject();

    if (isset($this->widgetSchema['problemepneumatique_list']))
    {
      $this->setDefault('problemepneumatique_list', $this->object->problemepneumatique->getPrimaryKeys());
    }

    if (isset($this->widgetSchema['positioneclairage_list']))
    {
      $this->setDefault('positioneclairage_list', $this->object->positioneclairage->getPrimaryKeys());
    }

    if (isset($this->widgetSchema['problememoteur_list']))
    {
      $this->setDefault('problememoteur_list', $this->object->problememoteur->getPrimaryKeys());
    }

    if (isset($this->widgetSchema['problemeniveau_list']))
    {
      $this->setDefault('problemeniveau_list', $this->object->problemeniveau->getPrimaryKeys());
    }

    if (isset($this->widgetSchema['problemecarrosserie_list']))
    {
      $this->setDefault('problemecarrosserie_list', $this->object->problemecarrosserie->getPrimaryKeys());
    }

    if (isset($this->widgetSchema['problemeeclairage_list']))
    {
      $this->setDefault('problemeeclairage_list', $this->object->problemeeclairage->getPrimaryKeys());
    }

    if (isset($this->widgetSchema['problemefreins_list']))
    {
      $this->setDefault('problemefreins_list', $this->object->problemefreins->getPrimaryKeys());
    }

    if (isset($this->widgetSchema['positioncarrosserie_list']))
    {
      $this->setDefault('positioncarrosserie_list', $this->object->positioncarrosserie->getPrimaryKeys());
    }

    if (isset($this->widgetSchema['positionpneumatique_list']))
    {
      $this->setDefault('positionpneumatique_list', $this->object->positionpneumatique->getPrimaryKeys());
    }

  }

  protected function doSave($con = null)
  {
    $this->saveproblemepneumatiqueList($con);
    $this->savepositioneclairageList($con);
    $this->saveproblememoteurList($con);
    $this->saveproblemeniveauList($con);
    $this->saveproblemecarrosserieList($con);
    $this->saveproblemeeclairageList($con);
    $this->saveproblemefreinsList($con);
    $this->savepositioncarrosserieList($con);
    $this->savepositionpneumatiqueList($con);

    parent::doSave($con);
  }

  public function saveproblemepneumatiqueList($con = null)
  {
    if (!$this->isValid())
    {
      throw $this->getErrorSchema();
    }

    if (!isset($this->widgetSchema['problemepneumatique_list']))
    {
      // somebody has unset this widget
      return;
    }

    if (null === $con)
    {
      $con = $this->getConnection();
    }

    $existing = $this->object->problemepneumatique->getPrimaryKeys();
    $values = $this->getValue('problemepneumatique_list');
    if (!is_array($values))
    {
      $values = array();
    }

    $unlink = array_diff($existing, $values);
    if (count($unlink))
    {
      $this->object->unlink('problemepneumatique', array_values($unlink));
    }

    $link = array_diff($values, $existing);
    if (count($link))
    {
      $this->object->link('problemepneumatique', array_values($link));
    }
  }

  public function savepositioneclairageList($con = null)
  {
    if (!$this->isValid())
    {
      throw $this->getErrorSchema();
    }

    if (!isset($this->widgetSchema['positioneclairage_list']))
    {
      // somebody has unset this widget
      return;
    }

    if (null === $con)
    {
      $con = $this->getConnection();
    }

    $existing = $this->object->positioneclairage->getPrimaryKeys();
    $values = $this->getValue('positioneclairage_list');
    if (!is_array($values))
    {
      $values = array();
    }

    $unlink = array_diff($existing, $values);
    if (count($unlink))
    {
      $this->object->unlink('positioneclairage', array_values($unlink));
    }

    $link = array_diff($values, $existing);
    if (count($link))
    {
      $this->object->link('positioneclairage', array_values($link));
    }
  }

  public function saveproblememoteurList($con = null)
  {
    if (!$this->isValid())
    {
      throw $this->getErrorSchema();
    }

    if (!isset($this->widgetSchema['problememoteur_list']))
    {
      // somebody has unset this widget
      return;
    }

    if (null === $con)
    {
      $con = $this->getConnection();
    }

    $existing = $this->object->problememoteur->getPrimaryKeys();
    $values = $this->getValue('problememoteur_list');
    if (!is_array($values))
    {
      $values = array();
    }

    $unlink = array_diff($existing, $values);
    if (count($unlink))
    {
      $this->object->unlink('problememoteur', array_values($unlink));
    }

    $link = array_diff($values, $existing);
    if (count($link))
    {
      $this->object->link('problememoteur', array_values($link));
    }
  }

  public function saveproblemeniveauList($con = null)
  {
    if (!$this->isValid())
    {
      throw $this->getErrorSchema();
    }

    if (!isset($this->widgetSchema['problemeniveau_list']))
    {
      // somebody has unset this widget
      return;
    }

    if (null === $con)
    {
      $con = $this->getConnection();
    }

    $existing = $this->object->problemeniveau->getPrimaryKeys();
    $values = $this->getValue('problemeniveau_list');
    if (!is_array($values))
    {
      $values = array();
    }

    $unlink = array_diff($existing, $values);
    if (count($unlink))
    {
      $this->object->unlink('problemeniveau', array_values($unlink));
    }

    $link = array_diff($values, $existing);
    if (count($link))
    {
      $this->object->link('problemeniveau', array_values($link));
    }
  }

  public function saveproblemecarrosserieList($con = null)
  {
    if (!$this->isValid())
    {
      throw $this->getErrorSchema();
    }

    if (!isset($this->widgetSchema['problemecarrosserie_list']))
    {
      // somebody has unset this widget
      return;
    }

    if (null === $con)
    {
      $con = $this->getConnection();
    }

    $existing = $this->object->problemecarrosserie->getPrimaryKeys();
    $values = $this->getValue('problemecarrosserie_list');
    if (!is_array($values))
    {
      $values = array();
    }

    $unlink = array_diff($existing, $values);
    if (count($unlink))
    {
      $this->object->unlink('problemecarrosserie', array_values($unlink));
    }

    $link = array_diff($values, $existing);
    if (count($link))
    {
      $this->object->link('problemecarrosserie', array_values($link));
    }
  }

  public function saveproblemeeclairageList($con = null)
  {
    if (!$this->isValid())
    {
      throw $this->getErrorSchema();
    }

    if (!isset($this->widgetSchema['problemeeclairage_list']))
    {
      // somebody has unset this widget
      return;
    }

    if (null === $con)
    {
      $con = $this->getConnection();
    }

    $existing = $this->object->problemeeclairage->getPrimaryKeys();
    $values = $this->getValue('problemeeclairage_list');
    if (!is_array($values))
    {
      $values = array();
    }

    $unlink = array_diff($existing, $values);
    if (count($unlink))
    {
      $this->object->unlink('problemeeclairage', array_values($unlink));
    }

    $link = array_diff($values, $existing);
    if (count($link))
    {
      $this->object->link('problemeeclairage', array_values($link));
    }
  }

  public function saveproblemefreinsList($con = null)
  {
    if (!$this->isValid())
    {
      throw $this->getErrorSchema();
    }

    if (!isset($this->widgetSchema['problemefreins_list']))
    {
      // somebody has unset this widget
      return;
    }

    if (null === $con)
    {
      $con = $this->getConnection();
    }

    $existing = $this->object->problemefreins->getPrimaryKeys();
    $values = $this->getValue('problemefreins_list');
    if (!is_array($values))
    {
      $values = array();
    }

    $unlink = array_diff($existing, $values);
    if (count($unlink))
    {
      $this->object->unlink('problemefreins', array_values($unlink));
    }

    $link = array_diff($values, $existing);
    if (count($link))
    {
      $this->object->link('problemefreins', array_values($link));
    }
  }

  public function savepositioncarrosserieList($con = null)
  {
    if (!$this->isValid())
    {
      throw $this->getErrorSchema();
    }

    if (!isset($this->widgetSchema['positioncarrosserie_list']))
    {
      // somebody has unset this widget
      return;
    }

    if (null === $con)
    {
      $con = $this->getConnection();
    }

    $existing = $this->object->positioncarrosserie->getPrimaryKeys();
    $values = $this->getValue('positioncarrosserie_list');
    if (!is_array($values))
    {
      $values = array();
    }

    $unlink = array_diff($existing, $values);
    if (count($unlink))
    {
      $this->object->unlink('positioncarrosserie', array_values($unlink));
    }

    $link = array_diff($values, $existing);
    if (count($link))
    {
      $this->object->link('positioncarrosserie', array_values($link));
    }
  }

  public function savepositionpneumatiqueList($con = null)
  {
    if (!$this->isValid())
    {
      throw $this->getErrorSchema();
    }

    if (!isset($this->widgetSchema['positionpneumatique_list']))
    {
      // somebody has unset this widget
      return;
    }

    if (null === $con)
    {
      $con = $this->getConnection();
    }

    $existing = $this->object->positionpneumatique->getPrimaryKeys();
    $values = $this->getValue('positionpneumatique_list');
    if (!is_array($values))
    {
      $values = array();
    }

    $unlink = array_diff($existing, $values);
    if (count($unlink))
    {
      $this->object->unlink('positionpneumatique', array_values($unlink));
    }

    $link = array_diff($values, $existing);
    if (count($link))
    {
      $this->object->link('positionpneumatique', array_values($link));
    }
  }

}
